﻿using System;
using System.Windows.Forms;
using StockLib;

namespace StockUI
{
    public partial class FormReport
    {
        // 处理快捷键
        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            //Trace.WriteLine("Report.ProcessCmdKey " + keyData);

            if (!IsActive)
                return base.ProcessCmdKey(ref msg, keyData);

            if (gridReport.SelectedRows.Count <= 0)
                return base.ProcessCmdKey(ref msg, keyData);

            Stock stock = gridReport.SelectedRows[0].DataBoundItem as Stock;
            switch (keyData)
            {
                case Keys.F10:          // 基本资料
                    SendMessage(FindFormChild("Base"), new FormNotifyMessage("Base.Show", stock));
                    return true;

                case Keys.Enter:        // 走势图
                    SendMessage(FindFormChild("Graph"), new FormNotifyMessage("Graph.Show", stock));
                    return true;

                case Keys.Control | Keys.R:     // 所属板块
                    DialogStockBlockList dialogBlockList = new DialogStockBlockList();
                    dialogBlockList.Stock = stock;
                    dialogBlockList.ShowDialog(this);
                    return true;

                case Keys.Control | Keys.Z:     // 加入板块
                    DialogStockBlockPut dialogBlockPut = new DialogStockBlockPut();
                    dialogBlockPut.Stock = stock;
                    dialogBlockPut.ShowDialog(this);
                    return true;

                case Keys.Alt | Keys.Z:         // 加入自选股
                    if (!StockBlockGroupCustom.Instance.ZXGBlock.ContainsKey(stock.CodeKey))
                    {
                        StockBlockGroupCustom.Instance.ZXGBlock.Add(stock.CodeKey, stock);
                        StockBlockGroupCustom.Instance.ZXGBlock.StockNumber = StockBlockGroupCustom.Instance.ZXGBlock.Count;
                    }
                    return true;

                case Keys.Delete:
                    if (StockBlockGroupCustom.Instance.ContainsKey(currentBlockId))
                    {
                        StockBlock domain = StockBlockGroupCustom.Instance[currentBlockId];
                        if (domain.ContainsKey(stock.CodeKey))
                        {
                            domain.Remove(stock.CodeKey);
                            domain.StockNumber = domain.Count;
                            BlockStockDataRefrech();
                        }
                    }
                    return true;
            }

            return base.ProcessCmdKey(ref msg, keyData);
        }


        // 处理通知消息
        protected override void ProcessNotifyMessage(FormNotifyMessage msg)
        {
            switch (msg.Message)
            {
                case "Report.Show":     //显示分类行情
                    string blockLabel = msg.Param1.ToString();
                    string blockId = msg.Param2.ToString();
                    if (blockId != currentBlockId)
                    {
                        BlockSwitch(blockLabel, blockId);
                    }
                    break;
            }
        }
    }
}
